<template>
	<div class="app-content">
		<div class="app-content-body fade-in-up" :class="[$store.state.menu.isNextMenuShow ? 'nextmenushow' : 'nextmenuhide']">
			<div class="breadcrumb-nav" v-if="isShowTitle">
				<!-- <span class="breadcrumb-title">{{title}}</span> -->
				<el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb-list">
					<el-breadcrumb-item :to="{ path: item.path }" v-for="(item, index) in $store.state.menu.breadcrumbArr" :key="index">{{item.title}}</el-breadcrumb-item>
				</el-breadcrumb>
			</div>
			<div ref="model_wrap" class="model-wrap" :style="{height: isShowTitle ? $store.state.menu.device.height - 45 + 'px' : $store.state.menu.device.height + 'px' }">
				<div class="model-wrap-bg" :style="{minHeight: isShowTitle ? $store.state.menu.device.height - 45 - 20 + 'px': $store.state.menu.device.height - 20 + 'px'}">
					<keep-alive include="ShopList">
						<transition name="fade-transform" mode="out-in">
							<router-view v-if="$store.state.menu.isRouterAlive"></router-view>
						</transition>
					</keep-alive>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import { mapMutations } from 'vuex';
	export default {
		name: "MainContent",
		data() {
			return {
				title: '', // 面包屑的标题
			};
		},
		computed: {
			isShowTitle() {
				let title = this.title
				if(title == '首页') {
					return false
				} else {
					return true
				}
			}
		},
		watch: {
			'$route' () {
				this.init()
				this.$refs['model_wrap'].scroll(0, 0)
			},
			'$store.state.menu.isRouterAlive' (value) {
				if(!value) {
					this.$nextTick(function() {
						this.setRouterAlive(true)
					})
				}

			}
		},
		mounted() {
			this.init()
		},
		created() {},
		methods: {
			...mapMutations([
				'setBreadcrumbArr',
				'setRouterAlive'
			]),
			init() {
				let routeParams = this.$route
				if(routeParams.meta && routeParams.meta.title) {
					this.title = routeParams.meta.title // 初始化title
					let routeItem = {
						title: this.title,
						path: routeParams.path,
						fullPath: routeParams.fullPath
					}
					
					this.setBreadcrumbArr(routeItem)
				}
			}
		},
	};
</script>
<style lang="scss">
	.app-content {
		height: 100%;
		background-color: #F5F5F5
	}
	
	.app-content-body {
		height: 100%;
		box-sizing: border-box;
	}
	
	.nextmenuhide {
		padding-left: 90px;
	}
	
	.nextmenushow {
		padding-left: 200px;
	}
	
	.breadcrumb-nav {
		display: flex;
		align-items: center;
		padding-left: 25px;
		padding-right: 10px;
		height: 45px;
		color: #606266;
		background: #ffffff;
		text-align: left;
		border-bottom: 1px solid #E4E7ED;
		.breadcrumb-title {
			font-weight: 600;
		}
		.breadcrumb-list {
			// padding-left: 25px;
			font-size: 12px;
		}
	}
</style>